<!--{template common/header_simple_start}-->
<link href="static/css/common.css?{VERHASH}" rel="stylesheet" media="all">
<script type="text/javascript" src="static/js/jquery.leftDrager.js?{VERHASH}"></script>
<style>
	html,
	body {
		overflow: hidden;
		background: #FBFBFB;
	}
	
	.bs-left-container {
		width: 120px;
	}
	
	.bs-main-container {
		margin-left: 120px;
		overflow: auto;
	}
</style>
<!--{template common/header_simple_end}-->

<div class="bs-container clearfix">
	<div class="bs-left-container  clearfix">
		<!--{template left}-->
	</div>
	<div class="left-drager">
		<div class="left-drager-op">
			<div class="left-drager-sub"></div>
		</div>
	</div>

	<div class="bs-main-container  clearfix">
		<div class="main-header">
			<ul class="nav nav-pills nav-pills-bottomguide">
				<li>
					<a href="{BASESCRIPT}?mod=setting&operation=qywechat">{lang enterprise_binding}</a>
				</li>
				<li>
					<a href="{BASESCRIPT}?mod=setting&op=assistant">{lang enterprise_little_helper}</a>
				</li>
				<li class="active">
					<a href="{BASESCRIPT}?mod=setting&op=wxsyn">{lang data_synchronization}</a>
				</li>
			</ul>

		</div>
		<div class="main-content" style="padding:15px">
			<ul class="help-block" style="line-height:2">
				{lang seeting_wxsyn_bound_state}
			</ul>
			<button class="btn btn-width btn-info ml20" data-loading-text="{lang are_synchronized}" onclick="qywechat_syn_org(this)">{lang start_sync_weixin}</button>

			<div id="syn_info" class="alert"></div>

		</div>
	</div>
</div>
<script type="text/javascript">
	jQuery('.left-drager').leftDrager_layout();

	function qywechat_syn_org(button, i) {
		if(!i) i = 0;
		var el = jQuery(button);
		if(i == 0) el.button('loading');
		jQuery.getJSON('{ADMINSCRIPT}?mod=setting&op=wxsyn&do=qiwechat_syn_org&i=' + i, function(json) {
			if(json.error) {
				el.html(json.error);
				window.setTimeout(function() { el.html('{lang start_sync_section_weixin}');
					el.button('reset'); }, 1000);
			} else if(json.msg == 'continue') {
				jQuery('#syn_info').append('<p>' + json.message + '</p>');
				jQuery('.bs-main-container').scrollTop(jQuery('.main-content').height());
				window.setTimeout(function() { qywechat_syn_org(button, json.start) }, 500);
			} else if(json.msg == 'success') {
				jQuery('#syn_info').append('{lang synchronization_section_p}');
				jQuery('.bs-main-container').scrollTop(jQuery('.main-content').height());
				qywechat_syn_user(button, 0);
			}
		});
	}

	function qywechat_syn_user(button, i) {
		if(!i) i = 0;
		var el = jQuery(button);
		if(i == 0) el.button('loading');
		jQuery.getJSON('{ADMINSCRIPT}?mod=setting&op=wxsyn&do=qiwechat_syn_user&i=' + i, function(json) {
			if(json.error) {
				jQuery('#syn_info').append('<p>' + json.error + '</p>');
				window.setTimeout(function() { el.html('{lang synchronization_weinxin}');
					el.button('reset'); }, 1000);
			} else if(json.msg == 'continue') {
				if(json.message) jQuery('#syn_info').append('<p>' + json.message + '</p>');
				jQuery('.bs-main-container').scrollTop(jQuery('.main-content').height());
				window.setTimeout(function() { qywechat_syn_user(button, json.start) }, 500);
			} else if(json.msg == 'success') {
				jQuery('#syn_info').append('{lang synchronization_success}');
				window.setTimeout(function() { el.html('{lang synchronization_weinxin_success}'); }, 1000);
			}
		});
	}
</script>
<script src="static/bootstrap/js/bootstrap.min.js?{VERHASH}"></script>

<!--{template common/footer_simple}-->